package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fly.domain.Vehicles;
import com.ruoyi.fly.domain.vo.*;
import com.ruoyi.fly.service.VehiclesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆信息Controller
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/vehicles")
@Api(tags = "车辆管理")
public class VehiclesController extends BaseController {
    @Autowired
    private VehiclesService vehiclesService;

    /**
     * 查询车辆信息列表
     */
    @ApiOperation(value = "查询车辆信息列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody VehiclesSearchVo vehiclesSearchVo) {
        List<VehiclesVo> list = vehiclesService.selectPcVehiclesList(vehiclesSearchVo);
        return getDataTable(list);
    }

    @ApiOperation(value = "查询车辆信息列表")
    @PostMapping("/selectList")
    public R selectList(@RequestBody VehiclesSearchVo vehiclesSearchVo) {
        List<VehiclesVo> list = vehiclesService.selectList(vehiclesSearchVo);
        List<BackVo> backVoList = new ArrayList<>();
        for (VehiclesVo vehiclesVo : list) {
            BackVo backVo = new BackVo();
            backVo.setId(String.valueOf(vehiclesVo.getId()));
            backVo.setValue(vehiclesVo.getLicensePlate());
            backVoList.add(backVo);
        }
        return R.ok(backVoList);
    }


    /**
     * 根据车辆id获取车辆信息
     */
    @ApiOperation(value = "根据车辆id获取车辆信息")
    @GetMapping(value = "/select/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(vehiclesService.selectPcVehiclesById(id));
    }

    /**
     * 增加车辆
     */
    @ApiOperation(value = "增加车辆")
    @PostMapping("/add")
    public R add(@RequestBody Vehicles vehicles) {
        return vehiclesService.insertPcVehicles(vehicles);
    }


    /**
     * 修改车辆信息
     */
    @ApiOperation(value = "修改车辆信息")
    @PostMapping("/edit")
    public R edit(@RequestBody Vehicles vehicles) {
        return vehiclesService.updatePcVehicles(vehicles);
    }

    /**
     * 删除车辆信息
     */
    @ApiOperation(value = "删除车辆信息")
    @PostMapping("/delete")
    public R remove(@RequestBody DeleteVo deleteVo) {
        return vehiclesService.deletePcVehiclesByIds(deleteVo.getIds());
    }

    /**
     * 添加车辆产品或服务
     */
    @ApiOperation(value = "添加车辆产品或服务")
    @PostMapping("/addProductOrServer")
    public R addProduct(@RequestBody ProductInsertVo productInsertVo) {
        return vehiclesService.insertVehiclesProductOrServer(productInsertVo);
    }

    /**
     * 查看车辆下的产品或服务
     */
    @ApiOperation(value = "查看车辆下的产品或服务")
    @PostMapping("/selVehiclesList")
    public R selVehiclesList(@RequestBody StoreProductServerVo storeProductServerVo){
        return vehiclesService.selectVehiclesProductOrServer(storeProductServerVo);
    }

    /**
     * 删除车辆下的产品或服务
     */
    @ApiOperation(value = "删除车辆下的产品或服务")
    @PostMapping("/deleteProductOrServer")
    public R deleteProductOrServer(@RequestBody ProductDeleteVo productDeleteVo){
        return vehiclesService.deleteVehiclesProductOrServer(productDeleteVo);
    }
}
